<script setup>
import { getTab3EvalSubmit, getTab3EvalImg,getTab3TrainSubmit,getTab3TrainImg } from "@/api/index.js"
import { ref } from 'vue'
const epochImage = ref('')
const matrixImage = ref('')
const handleTrainSubmit = () => {
    console.log("handleTrainSubmit")
    getTab3TrainSubmit().then(() => {
      console.log("handleTrainSubmi")
      getTab3TrainImg('epoch_loss.png').then((res) => {
          // console.log("getTab0List",res)
          epochImage.value ='http://127.0.0.1:5000/tab3/epoch_lossDownload/epoch_loss.png'
          console.log("epochImage",epochImage)
          // imageUrlList.value = modifiedUrls
          // console.log("imageUrlList",imageUrlList.value)
        })
      })
  }
  const handleEvalSubmit = () => {
    console.log("handleEvalSubmit")
    getTab3EvalSubmit().then(() => {
      getTab3EvalImg('matrix.png').then((res) => {
          console.log("getTab0List",res)
          matrixImage.value = 'http://127.0.0.1:5000/tab3/matrixDownload/matrix.png'
          console.log("matrixImage",matrixImage)
          // const modifiedUrls = res.map(item => 'http://127.0.0.1:5000/tab0/Dresult_L/download/' + item.imageName)
          // imageUrlList.value = modifiedUrls
          // console.log("imageUrlList",imageUrlList.value)
        })
      })
  }
</script>

<template>
  <div class="body-content">
    <!-- 第一行 -->
    <div>
      <div class="title">
        检测模型训练
      </div>
      <div class="line">
        <el-steps :active="3" align-center>
        <el-step title="训练参数设置"/>
        <el-step title="训练过程可视化"/>
        <el-step title="综合指标分析"/>
      </el-steps>
      </div>
    </div>
    <!-- 第二行 -->
    <div>
      <el-row style="flex">
        <div class="first-box">
        <div class="box-title">
          1.频域增强参数设置
        </div>
        <div>
          <div class="laber">
    <div class="input-columns">
      <div class="input-column">
        <div class="input-container">
          <label class="input-lable">数据集</label>
            <select class="model-select-data">
              <option value="DAGA" selected>DAGA</option>
              <option value="AAPD" >AAPD</option>
              <option value="KolektorSDD2" >KolektorSDD2</option>
              <option value="MTD" >MTD</option>
           
          </select>
        </div>
        <div class="input-container">
          <label class="input-lable">检测模型</label>
          <select class="model-select-data">
              <option value="Agg" selected>Agg</option>
              <option value="resnet" selected>resnet</option>
           
          </select>
        </div>
        <div class="input-container">
          <label class="input-lable">预训练</label>
          <select class="model-select-data">
              <option value="Agg" selected>是/否</option>
              <option value="yes" selected>是</option>
              <option value="no" selected>否</option>
           
          </select>
        </div>
        <div class="input-container">
          <label class="input-lable">训练次数</label>
          <div class="input-box">
            <input type="text"  class="input-field" placeholder="500">
          </div>
        </div>
       
      </div>
      <div class="input-column">
        <div class="input-container">
          <label class="input-lable">优化器</label>
          <select class="model-select-data">
          <option value="resnet" selected>Adam/SGD</option>
        </select>
        </div>
        <div class="input-container">
          <label class="input-lable">动量</label>
          <div class="input-box">
            <input type="text"  class="input-field" placeholder="0.9">
          </div>
        </div>
        <div class="input-container">
          <label class="input-lable">学习率</label>
          <div class="input-box">
            <input type="text"  class="input-field" placeholder="0.0001">
          </div>
        </div>
        <div class="input-container">
          <label class="input-lable">下降方式</label>
          <select class="model-select-data">
            <option value="resnet" selected>Step/Cos</option>
          </select>

        </div>
       
      </div>
    </div>
  </div>
        </div>
         <div class="begin" @click="handleTrainSubmit">开始训练</div>
       </div>
       <!-- 第二个 -->
      <div class="second-box">
        <div class="box-title">
          2. 训练过程可视化
        </div>
        <div class="detailed-content">
          <!-- 左侧部分，占据2/5 -->
       
          <div class="left-content">
            <div class="box-blue3">
            <div v-if="epochImage==''" ></div>
            <img else style="width: 600px; height:200px" :src="epochImage" />
            </div>
            <div class="box-title">loss函数</div>
            <div class="inner-button3">
             
        </div>
        <!-- <div class="box-title">
          增强图像展示
        </div> -->
          </div>
          <!-- 右侧部分，占据3/5 -->
          <div class="right-content">
            <!-- 第一行，水平居中显示的图像生成记录 -->
            <div class="box-title">
              图像增强记录
            </div>
            <!-- 表格 -->
            <table class="image-table">
  <tbody>
    <tr>
      <td class="deep-blue-row">检测类型</td>
      <td class="blue-row">语义分割</td>
    </tr>
    <tr>
      <td class="deep-blue-row">名称</td>
      <td class="white-row">铝合金零部件检测</td>
    </tr>
    <tr>
      <td class="deep-blue-row">主模型名称</td>
      <td class="blue-row">U-Net</td>
    </tr>
    <tr>
      <td class="deep-blue-row">数据集</td>
      <td class="white-row">AAPD</td>
    </tr>
    <tr>
      <td class="deep-blue-row">训练次数</td>
      <td class="blue-row">500</td>
    </tr>
  </tbody>
</table>

            <!-- 按钮 -->
            <div style="margin: 10px;">进度：
              <el-progress :text-inside="true" :stroke-width="26" :percentage="70" />
            </div>
          </div>
        </div>
      </div>

       
      </el-row>
    </div>
    <!-- 第三行 -->
    <div>
        <el-row  style="display: flex;justify-content: space-between;margin:10px; 
  border: gray solid 1px;" >
          <!-- 第一列 -->
          <div style="order: 0 ;">
            <div class="box-title">
              3. 综合指标分析
            </div>
            <div style="margin:20px 30px;">
              <div style="margin:20px 30px;">
                  <span>数据集选择：</span>
                <select class="model-select">
                <option value="cyclegan" selected>DAGM</option>
                </select>
              </div>
              <div style="margin:20px 30px;">
                  <span>检测模型选择：</span>
                <select class="model-select">
                  <option value="cyclegan" selected>Agg</option>
                </select>
              </div>
              <div >
                <div style="display: inline-block;border: black solid 1px;;
                  width: 80px;
                  height: 30px;
                  background-color: aliceblue;margin:20px 30px;"  @click="handleEvalSubmit">开始测试</div>
              <div  style="display: inline-block;border: black solid 1px;;
                width: 80px;
                height: 30px;
                background-color: aliceblue;"  >保存权重</div>
              </div>
              
             
            </div>
          </div>
       
          <!--第二列 -->
        <div>
          <div>
            <div class="box-title">
            数据集A
          </div>
          <div style=" display: flex;
            justify-content: center;
            align-items: center;
            background-color: #7aafe4;
            width: 450px;
            height: 390px;
            margin: 0px 40px;
            margin-top：10px;
            padding-top: 10px;"
            
           >
              <div class="inner-button2">
                <img style="height: 400px; width:450px;" :src="matrixImage">
              </div>
          </div>
          <div class="box-title">
            混淆矩阵
          </div>
          </div>
          
        </div>
          <!--第三列 -->
        <div> 
          <!-- 第一行 -->
          <div>
            <div style="display: flex; justify-content: space-between;">
              <div>
               
                <div style=" display: flex;
                  justify-content: center;
                  align-items: center;
                  /* background-color: #7aafe4;  */
                  width: 300px;
                  height: 130px;
                  margin: 0px 40px;">
                    
                      <img style="margin-top: 60px; height: 180px; width:350px;" src="@/assets/test2.png">
                </div>
              
                <div class="box-title" style="margin-top: 60px;">
                  Accuracy
                </div>
              </div>

              <div>
                <div>
               
               <div style=" display: flex;
                 justify-content: center;
                 align-items: center;
                 /* background-color: #7aafe4;  */
                 width: 300px;
                 height: 130px;
                 margin: 0px 40px;">
                   
                     <img style="margin-top: 60px; height: 180px; width:350px;" src="@/assets/test2.png">
               </div>
             
               <div class="box-title" style="margin-top: 60px;">
                 Recall
               </div>
             </div>
             </div> 
             </div> 
             <div style="display: flex; justify-content: space-between;">
              <div>
                <div>
               
               <div style=" display: flex;
                 justify-content: center;
                 align-items: center;
                 /* background-color: #7aafe4;  */
                 width: 300px;
                 height: 130px;
                 margin: 0px 40px;">
                   
                     <img style="margin-top: 60px; height: 180px; width:350px;" src="@/assets/test2.png">
               </div>
             
               <div class="box-title" style="margin-top: 60px;">
                 Precision
               </div>
             </div>
              </div>

              <div>
                <div>
               
               <div style=" display: flex;
                 justify-content: center;
                 align-items: center;
                 /* background-color: #7aafe4;  */
                 width: 300px;
                 height: 130px;
                 margin: 0px 40px;">
                   
                     <img style="margin-top: 60px; height: 180px; width:350px;" src="@/assets/test2.png">
               </div>
             
               <div class="box-title" style="margin-top: 60px;">
                 F1-Score
               </div>
             </div>
             </div> 
             </div> 
             
           </div>

        </div>

      </el-row>
    </div>
  </div>
</template>
<style scoped>
.body-content{
  /* max-height: calc(100vh - 90px); */
}
.title{
  font-size: 19px;
  font-weight: 400;
  margin:10px
}
.line{
  margin-bottom: 1px;
}
::v-deep .el-step__head.is-finish {
    color: #1a1b1d;
    border-color: #2a2c2f;
}
::v-deep .el-step__title.is-finish {
  color: #1a1b1d;
}
.box-title{
  font-size: 16px;
  font-weight: 600;
  margin:10px;
  margin-bottom: 0px;
  text-align:center
}
.box-title-small{
  font-size: 12px;
  font-weight: 300;
  margin:5px;
  margin-bottom: 0px;
  text-align:center
}
.first-box{
  border: gray solid 1px;
  /* min-width: 300px; */
  margin:15px; 
}
.box-blue {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #5b9bd5;
  width: 200px;
  height: 200px;
  margin: 10px 40px;
}
.box-blue3 {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #5b9bd5;
  width: 300px;
  height: 200px;
  margin: 10px 40px;
}
.box-blue2 {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #5b9bd5;
  width: 400px;
  height: 200px;
  margin: 10px 40px;
}
.box-blue23 {
  display: flex;
  /* justify-content: center;
  align-items: center; */
  background-color: #5b9bd5;
  width: 400px;
  height: 200px;
  margin: 10px 40px;
}


.inner-button {
  width: 60px;
  height: 30px;
  background-color: aliceblue;
  display: flex;
  justify-content: center;
  align-items: center;
}
.inner-button2{
  /* color: white;
  font-size: 30px; */
}

.second-box{
  margin:15px; 
  border: gray solid 1px;
  /* min-width: 300px; */
}
.input-container {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.label {
  margin-right: 10px; 
}

.input-box {
  justify-content: center;
  align-items: center;
  display: flex;
  align-items: center;
  margin-left: 20px;
}

.input-field {
  width: 80px; /* 根据需要调整宽度 */
  padding: 5px;
  height: 25px;
  box-sizing: border-box;
  text-align: center;
}
.input-field2 {
  width: 40px; /* 根据需要调整宽度 */
  padding: 5px;
  height: 25px;
  box-sizing: border-box;
  text-align: center;
  margin-right:5px
}
  .input-field3 {
  width: 50px; /* 根据需要调整宽度 */
  padding: 5px;
  height: 25px;
  box-sizing: border-box;
  text-align: center;
  margin-left: 5px;
  }
.laber{
  margin-left: 35px;
}
.third-box{
  margin:10px; 
  border: gray solid 1px;
  /* min-width: 600px; */
  display: flex;
  flex-direction: column;
  align-items: center;
}
.begin{
  border: black solid 1px;;
  width: 80px;
  height: 30px;
  background-color: aliceblue;
  display: flex;
  justify-content: center;
  text-align:center;
  left: 50%;
  margin-top: 30px;
  
}

.row-container {
  display: flex;
  justify-content: space-between;
  margin: 0 -10px; /* 调整整体的 margin */
}

.first-box,
.second-box,
.third-box {
  flex: 1;
  margin:  10px; /* 调整每个盒子的 margin */
  display: flex;
  flex-direction: column;
  align-items: center;
}
.generation-options {
  display: flex;
  align-items: center;
}

.model-select {
  margin-right: 10px; /* 调整下拉框与按钮之间的间距 */
}
.model-select-data{
  /* margin-right: 10px; */
  width: 80px;
  margin-left: 20px; 

}
/* .begin {
  border: 1px solid black;
  padding: 5px 10px;
  cursor: pointer;
  background-color: aliceblue;
} */
.third-box {
  margin: 15px;
  border: gray solid 1px;
  min-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.detailed-content {
  display: flex;
  width: 100%;
}

.left-content {
  width: 55%; /* 占据2/5 */
}

.right-content {
  width: 45%; /* 占据3/5 */
}



.image-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}

th, td {
  border: 1px solid white;
  text-align: center;
  padding: 8px;
}

.deep-blue-row {
  background-color: #5b9bd5;
  color: white;
  height: 30px; 
}
.blue-row {
  background-color: #d2deef;
  color: black;
  height: 30px; 
}

.white-row {
  background-color: white;
  color: black;
  height: 30px; 
}

.action-buttons {
  display: flex;
  justify-content: right;
}

.delete-button,
.addToDatabase-button {
  border: 1px solid black;
  padding: 5px 10px;
  cursor: pointer;
  background-color: aliceblue;
  margin:10px;
}
.input-columns {
  display: flex;
  justify-content: space-between;
}

.input-column {
  flex: 1;
  margin-right: 20px; /* 调整间距根据需要 */
}
.input-lable{
  width: 70px;
}
</style>
